package com.example.workmanagerdemo;


import android.os.Handler;
import android.os.Looper;
import android.util.Log;

/**
 * author: tuyrt7 on 2020/12/11.
 * desc:
 */
public class TestData {
    private static final TestData ourInstance = new TestData();

    static TestData getInstance() {
        return ourInstance;
    }

    private TestData() {
    }

    public int getData() {
        return data;
    }

    public int data = -1;

    Handler handler = new Handler(Looper.getMainLooper());
    Runnable mRunnable = new Runnable() {
        @Override
        public void run() {
            data = data + 1;
            Log.i("aaaa", "TestData data: "+data);
            handler.postDelayed(this, 2000);
        }
    };

    public void update() {
        handler.postDelayed(mRunnable,2000);
    }

    public void release() {
        handler.removeCallbacks(mRunnable);
    }
}
